package com.inspinia.base.dao.aop;

import com.inspinia.base.dao.db.DataSourceTypeManager;
import com.inspinia.base.dao.db.DataSources;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 *
 * @author veblen
 * @date 2017/1/10
 */
@Aspect    // for aop
@Component // for auto scan
@Order(0)  // execute before @Transactional
@MapperScan(basePackages = {"com.inspinia.**.dao"})
public class MasterDataSourceInterceptor {

    @Pointcut("execution(* com.inspinia..dao..*(..))")
    public void dataSourceMaster() {
    }


    @Before("dataSourceMaster()")
    public void before(JoinPoint jp) {
//        System.out.println("进入通用dao,线程名：" + Thread.currentThread().getName());
        DataSourceTypeManager.set(DataSources.MASTER);
    }
}
